//
//  ViewController.m
//  微信share
//
//  Created by holier_zyq on 15/10/12.
//  Copyright © 2015年 holier_zyq. All rights reserved.
//

#import "ViewController.h"
#import "WXApi.h"
@interface ViewController ()<WXApiDelegate,UIAlertViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
     NSString *identifierStr = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    NSLog(@"%@", identifierStr);
    
    self.title = @"分享";
    self.view.backgroundColor = [UIColor cyanColor];
    
    UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
    shareButton.frame = CGRectMake(0, 0, 100, 100);
    shareButton.center = self.view.center;
    [shareButton addTarget:self action:@selector(handleButton) forControlEvents:UIControlEventTouchUpInside];
    shareButton.backgroundColor = [UIColor redColor];
    [shareButton setTitle:@"分享" forState:UIControlStateNormal];
    [self.view addSubview:shareButton];
    
    
}
- (void)handleButton {
    
    WXWebpageObject *web = [WXWebpageObject object];
    web.webpageUrl = @"http://www.baidu.com";
    
    WXMediaMessage *message = [WXMediaMessage message];
    [message setThumbImage:[UIImage imageNamed:@"3.png"]];
    message.title = @"送秋风";
    message.description = @"hndnfnfjjfkfflfrr";
    WXImageObject *ext = [WXImageObject object];
    ext.imageUrl = @"http://www.baidu.com";
    
    message.mediaObject = ext;
    
    SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    req.scene = WXSceneSession;
    
    [WXApi sendReq:req];

    
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        NSString *weiXinLink = @"http://mp.weixin.qq.com/mp/redirect?url=http%3A%2F%2Fitunes.apple.com%2Fcn%2Fapp%2Fwo-de-da-xue%2Fid789644892?mt=8rd";
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:weiXinLink]];
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
